Skip to content

Disposal#1039

Merged
henrydingliu merged 8 commits into
casact:disposal_rate_methodfrom
henrydingliu:disposal
Jun 21, 2026
Merged

Disposal#1039
henrydingliu merged 8 commits into
casact:disposal_rate_methodfrom
henrydingliu:disposal

Conversation

@henrydingliu

@henrydingliu henrydingliu commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary of Changes

Related GitHub Issue(s)

Additional Context for Reviewers

  • I passed tests locally for both code (uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)

Note

Medium Risk
Removing incr_to_cum on fit changes disposal-rate inputs for non-cumulative triangles, and ultimate/backend alignment in transform can alter forecasts if backends or shapes were previously inconsistent.

Overview
DisposalRate now validates sample_weight (ultimate) against X in both fit and transform via shared MethodBase.validate_weight, matching chainladder methods behavior when shapes may broadcast.

Fit no longer forces incr_to_cum() on the loss triangle before building disposal rates; it keeps a sorted copy as self.X_ and uses that for weights, parent super().fit, and the terminal disposal concat. Transform sets ultimate_ from the ultimate triangle’s latest diagonal on the same array backend as the fitted X_, instead of taking latest_diagonal without backend alignment.

MethodBase.validate_weight is refactored to a @staticmethod with Triangle type hints and a short docstring so DisposalRate can call it without duplicating logic.

Reviewed by Cursor Bugbot for commit 0c1830d. Bugbot is set up for automated code reviews on this repo. Configure here.

@henrydingliu henrydingliu marked this pull request as ready for review June 21, 2026 07:04
@henrydingliu henrydingliu merged commit 87857fe into casact:disposal_rate_method Jun 21, 2026
8 checks passed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0c1830d. Configure here.

#get backend
#calculate disposal rate triangle
self.xp = X.get_array_module()
self.X_ = X.sort_index()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted X_ mismatches disposal triangle

High Severity

fit stores a sorted triangle in self.X_ but builds disposal_rate_tri from the unsorted local X. Weights and super().fit then mix sorted self.X_.values with rates and ult.values tied to the original row order, so origins can be paired incorrectly whenever the index is not already sorted.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0c1830d. Configure here.

X = X.set_backend("numpy")
else:
X = X.copy().incr_to_cum()
X = X.copy()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed cumulative conversion in fit

Medium Severity

fit no longer calls incr_to_cum() on X after copying or setting the numpy backend. Disposal rates are cumulative paid (or similar) divided by ultimate; fitting on incremental values yields incorrect ratios and regression inputs for incremental triangles.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0c1830d. Configure here.

@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.24%. Comparing base (d6bbdac) to head (0c1830d).
⚠️ Report is 9 commits behind head on disposal_rate_method.

Files with missing lines Patch % Lines
chainladder/adjustments/disposal.py 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           disposal_rate_method    #1039      +/-   ##
========================================================
- Coverage                 89.25%   89.24%   -0.02%     
========================================================
  Files                        91       91              
  Lines                      5242     5233       -9     
  Branches                    666      666              
========================================================
- Hits                       4679     4670       -9     
- Misses                      394      396       +2     
+ Partials                    169      167       -2     
Flag Coverage Δ
unittests 89.24% <88.23%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant